package com.doge.walknovel.utils

import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit

fun rxInterval(
    period: Long, unit: TimeUnit = TimeUnit.MILLISECONDS,
    doOnNext: Consumer<Long>
): Disposable {
    return Observable.interval(period, unit)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .doOnNext(doOnNext)
        .subscribe()
}